package menu

import (
	"context"
	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"
	"fast-boot/app/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type PageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 菜单列表
func NewPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PageLogic {
	return &PageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PageLogic) Page(req *types.SysMenuPageReq) (resp []*types.SysMenuItem, err error) {
	items := make([]*model.SysMenuModel, 0)
	l.svcCtx.GormClient.GormDb.Model(&model.SysMenuModel{}).
		Order("id asc").Find(&items)

	return GetTreeList(items, 0), nil
}
